# Maintainer: Sébastien "Seblu" Luttringer
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: Eric Belanger <eric@archlinux.org>
# Contributor: John Proctor <jproctor@prium.net>

pkgname=pcre
pkgver=8.45
pkgrel=4
pkgdesc='A deprecated library that implements Perl 5-style regular expressions'
arch=('loong64' 'x86_64')
url='https://www.pcre.org/'
license=('BSD')
depends=('glibc' 'gcc-libs' 'readline' 'zlib' 'bzip2' 'bash')
provides=(libpcre{,16,32,posix,cpp}.so)
source=("https://sourceforge.net/projects/pcre/files/$pkgname/$pkgver/$pkgname-$pkgver.tar.bz2"{,.sig}
        '0001-pcre-JIT-compiler-update-for-Intel-CET.patch'
        '0002-pcre-Pass-mshstk-to-the-compiler-when-Intel-CET-is-enable.patch')
sha256sums=('4dae6fdcd2bb0bb6c37b5f97c33c2be954da743985369cddac3546e3218bffb8'
            'SKIP'
            '86e2fe1193f2dfaa5e3f3866c6be42a9cd0dddc5623f1658203a4dc73a4526f7'
            'a44ffb942d585c2c95036f91529063738b1c373fcd26a3e2dc95ae76b1f3c3db')
validpgpkeys=('45F68D54BBE23FB3039B46E59766E084FB0F43D8')  # Philip Hazel <ph10@hermes.cam.ac.uk>

prepare() {
  cd $pkgname-$pkgver
  # apply patch from the source array (should be a pacman feature)
  local src
  for src in "${source[@]}"; do
    src="${src%%::*}"
    src="${src##*/}"
    [[ $src = *.patch ]] || continue
    echo "Applying patch $src..."
    patch -Np1 < "../$src"
  done
  autoreconf -fi
}

build() {
  cd $pkgname-$pkgver
  ./configure \
    --prefix=/usr \
    --enable-unicode-properties \
    --enable-pcre16 \
    --enable-pcre32 \
    --disable-jit \
    --enable-pcregrep-libz \
    --enable-pcregrep-libbz2 \
    --enable-pcretest-libreadline
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  cd $pkgname-$pkgver
  make -j1 check
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install

  install -Dm644 LICENCE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

# vim:set sw=2 sts=-1 et:
